package com.leo.entity;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.entity.EntityFactory;
import com.almasb.fxgl.entity.SpawnData;
import com.almasb.fxgl.entity.Spawns;
import com.almasb.fxgl.entity.components.CollidableComponent;
import com.almasb.fxgl.texture.AnimatedTexture;
import com.almasb.fxgl.texture.AnimationChannel;
import com.leo.common.GameType;
import com.leo.component.TankComponent;
import javafx.util.Duration;

public class PlayerEntityFactory implements EntityFactory {

    @Spawns("player")
    public Entity createPlayer(SpawnData spawnData) {
        return FXGL.entityBuilder(spawnData)
                .type(GameType.PLAYER)
                .viewWithBBox(FXGL.texture("tank/H1U.png"))
                .with(new TankComponent())
                .with(new CollidableComponent(true))
                .build();
    }

    /**
     * 雪地
     *
     * @param spawnData
     * @return
     */
    @Spawns("snow")
    public Entity createSnow(SpawnData spawnData) {
        return FXGL.entityBuilder(spawnData)
                .type(GameType.SNOW)
                .viewWithBBox(FXGL.texture("map/snow.png"))
                .collidable()
                .neverUpdated()
                .build();
    }

    /**
     * 草坪
     *
     * @param spawnData
     * @return
     */
    @Spawns("greens")
    public Entity createGreens(SpawnData spawnData) {
        return FXGL.entityBuilder(spawnData)
                .type(GameType.GREENS)
                .viewWithBBox(FXGL.texture("map/greens.png"))
                .collidable()
                .zIndex(100)
                .neverUpdated()
                .build();
    }

    /**
     * 水
     *
     * @param spawnData
     * @return
     */
    @Spawns("sea")
    public Entity createSea(SpawnData spawnData) {
        AnimationChannel ac = new AnimationChannel(FXGL.image("map/sea_anim.png"), Duration.seconds(1), 2);
        AnimatedTexture at = new AnimatedTexture(ac);
        return FXGL.entityBuilder(spawnData)
                .type(GameType.SEA)
                .viewWithBBox(at.loop())
                .collidable()
                .build();
    }

    /**
     * 石头
     *
     * @param spawnData
     * @return
     */
    @Spawns("stone")
    public Entity createStone(SpawnData spawnData) {
        return FXGL.entityBuilder(spawnData)
                .type(GameType.STONE)
                .viewWithBBox(FXGL.texture("map/stone.png"))
                .collidable()
                .neverUpdated()
                .build();
    }

    /**
     * 土墙
     *
     * @param spawnData
     * @return
     */
    @Spawns("brick")
    public Entity createBrick(SpawnData spawnData) {
        return FXGL.entityBuilder(spawnData)
                .type(GameType.BRICK)
                .viewWithBBox(FXGL.texture("map/brick.png"))
                .collidable()
                .neverUpdated()
                .build();
    }
}
